﻿using System.Runtime.InteropServices;

namespace AESAlgorithm2DNet
{
    public class AlgorithmImage2D
    {
        [DllImport("AESAlgorithm2D.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern int Add();


        /// <summary>
		/// 基于东松脏污算法原理基础的脏污算法
		/// </summary>
		/// <param name="srcImage">输入图</param>
		/// <param name="srcImageW">输入图宽</param>
		/// <param name="srcImageH">输入图高</param>
		/// <param name="ch">图像深度</param>
		/// <param name="dist">判断距离</param>
		/// <param name="threshold">判断阈值</param>
		/// <param name="filter">过滤的值，按照合并的框的脏污像素大小</param>
		/// <param name="roiX">裁剪ROI的X</param>
		/// <param name="roiY">裁剪ROI的Y</param>
		/// <param name="roiRadius">如果这个数值大于0,则按照圆形裁剪，反之按照矩形裁剪</param>
		/// <param name="roiW">如果按照矩形裁剪，则这个参数生效，如果为0，则默认全图检索</param>
		/// <param name="roiH">如果按照矩形裁剪，则这个参数生效，如果为0，则默认全图检索</param>
		/// <param name="dstImage">结果图</param>
		/// <returns>测试流程OK则返回true</returns>
		[DllImport("AESAlgorithm2D.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern bool Stain(byte[]? srcImage, int srcImageW, int srcImageH, int ch,
            int dist, int threshold, int filter, int roiX, int roiY, int roiRadius, int roiW, int roiH,
            ref int stainNum,
            byte[]? dstImage = null);

        [DllImport("AESAlgorithm2D.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern bool SpliteCornersAndSort(float[] cornerX, float[] cornerY, int cornerNum, float maxScore);

        [DllImport("AESAlgorithm2D.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern bool FindManayWhiteBoxTheOneHaveBlackPix(byte[]? srcImage, int srcImageW, int srcImageH, int ch, int dist, ref float px, ref float py, byte[]? dstImage = null);



        [DllImport("LJZ.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern UInt32 LXS50EVKeyL1SeedToKey(UInt32 num, UInt32 seed);

        [StructLayout(LayoutKind.Sequential)]
        public struct FindRectParam
        {
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
            public int[] ROIx = new int[32];
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
            public int[] ROIy = new int[32];
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
            public int[] ROIw = new int[32];
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
            public int[] ROIh = new int[32];
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
            public int[] ROIthreshold = new int[32];

            public int mergeThreshold = 10; // 合并阈值，默认0
            public int selechCH = -1; // -1表示全部通道，0表示第一个通道，1表示第二个通道，2表示第三个通道
            public int roiNum = 5;
            public int miniArea = 0;
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32 * 4 * 2)]
            public int[] ROIFindConner = new int[32 * 4 * 2];

            public FindRectParam()
            {
            }
        };
        [DllImport("AESAlgorithm2D.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern bool FindRect(byte[] srcImage, int srcImageW, int srcImageH, int ch, FindRectParam param, byte[] dstImage);

    }
}
